home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / serweb03.zip / SERWEB.CPP < prev    next >
C/C++ Source or Header  |  1993-11-03  |  5KB  |  183 lines

  1. // serweb.cpp
  2. // Written by Gus Estrella (estrella@cass.ma02.bull.com)
  3. // 
  4. //
  5.  
  6. #include "stdafx.h"
  7. #include "serweb.h"
  8.  
  9. #include "mainfrm.h"
  10. #include "serwedoc.h"
  11. #include "serwevw.h"
  12.  
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char BASED_CODE THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CSerwebApp
  20.  
  21. BEGIN_MESSAGE_MAP(CSerwebApp, CWinApp)
  22.     //{{AFX_MSG_MAP(CSerwebApp)
  23.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  24.         // NOTE - the ClassWizard will add and remove mapping macros here.
  25.         //    DO NOT EDIT what you see in these blocks of generated code !
  26.     //}}AFX_MSG_MAP
  27.     // Standard file based document commands
  28.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  29.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  30. END_MESSAGE_MAP()
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CSerwebApp construction
  34.  
  35. CSerwebApp::CSerwebApp()
  36. {
  37.     // TODO: add construction code here,
  38.     // Place all significant initialization in InitInstance
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // The one and only CSerwebApp object
  43.  
  44. CSerwebApp NEAR theApp;
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CSerwebApp initialization
  48.  
  49. BOOL CSerwebApp::InitInstance()
  50. {
  51.     WSADATA wsaData;         // Winsock
  52.     int error;              // Winsock
  53.                                    
  54.        
  55.     // Initialize WINSOCK below ....
  56.     
  57.     HowManyClients = GetProfileInt("SERWEB","HowManyClients", 5);                                
  58.  
  59.     error = WSAStartup(WS_VERSION_REQD, &wsaData);
  60.     if (error != 0)
  61.       {                               
  62.           MessageBox(NULL,"WinSocket could not be initialized.  Please check", AfxGetAppName(), MB_OK);
  63.         WSACleanup();
  64.         return FALSE;
  65.       }                                                               
  66.     
  67.     if (( LOBYTE (wsaData.wVersion) < WS_VERSION_MAJOR) ||
  68.         ( LOBYTE (wsaData.wVersion) == WS_VERSION_MAJOR &&
  69.           HIBYTE (wsaData.wVersion) < WS_VERSION_MINOR) )
  70.       {
  71.         sprintf(buf, "Windows Sockets version %d.%d not supported by winsock.dll", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
  72.         MessageBox(NULL, buf,  AfxGetAppName(), MB_OK);   
  73.         WSACleanup();
  74.         return FALSE;   
  75.       }
  76.     
  77.     if (wsaData.iMaxSockets < (HowManyClients + 1))
  78.       {
  79.         sprintf(buf, "This application requires a minimun of %d supported sockets.  Close other network applications and restart or change the .INI file entry for Number of Clients.", MIN_SOCKETS_REQD);
  80.         MessageBox(NULL, buf,  AfxGetAppName(), MB_OK);
  81.         WSACleanup();
  82.         return FALSE;   
  83.       }
  84.            
  85.     // Continue with the window initialization now ......
  86.        
  87.         // Standard initialization
  88.     // If you are not using these features and wish to reduce the size
  89.     //  of your final executable, you should remove from the following
  90.     //  the specific initialization routines you do not need.
  91.  
  92.     SetDialogBkColor();        // set dialog background color to gray
  93.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  94.  
  95.     // Register the application's document templates.  Document templates
  96.     //  serve as the connection between documents, frame windows and views.
  97.  
  98.     AddDocTemplate(new CSingleDocTemplate(IDR_MAINFRAME,
  99.             RUNTIME_CLASS(CSerwebDoc),
  100.             RUNTIME_CLASS(CMainFrame),     // main SDI frame window
  101.             RUNTIME_CLASS(CSerwebView)));
  102.  
  103.  
  104.     // create a new (empty) document
  105.     OnFileNew();
  106.  
  107.     if (m_lpCmdLine[0] != '\0')
  108.     {
  109.         // TODO: add command line processing here
  110.     }
  111.  
  112.     return TRUE;
  113. }
  114.  
  115. /////////////////////////////////////////////////////////////////////////////
  116. BOOL CSerwebApp::ExitInstance()      
  117. {
  118.     int error;              // Winsock
  119.                  
  120.    error = WSACleanup();                      // Winsock code
  121.     if (error != 0)
  122.       {                               
  123.         sprintf(buf, "Windows Sockets error %d.", error);
  124.         MessageBox(NULL, buf,  AfxGetAppName(), MB_OK);   
  125.       }
  126.    
  127.    if (m_pMainWnd != NULL)       
  128.       VERIFY(m_pMainWnd->DestroyWindow());
  129.  
  130.    return CWinApp::ExitInstance();
  131. }             
  132.       
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CAboutDlg dialog used for App About
  135.  
  136. class CAboutDlg : public CDialog
  137. {
  138. public:
  139.     CAboutDlg();
  140.  
  141. // Dialog Data
  142.     //{{AFX_DATA(CAboutDlg)
  143.     enum { IDD = IDD_ABOUTBOX };
  144.     //}}AFX_DATA
  145.  
  146. // Implementation
  147. protected:
  148.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  149.     //{{AFX_MSG(CAboutDlg)
  150.         // No message handlers
  151.     //}}AFX_MSG
  152.     DECLARE_MESSAGE_MAP()
  153. };
  154.  
  155. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  156. {
  157.     //{{AFX_DATA_INIT(CAboutDlg)
  158.     //}}AFX_DATA_INIT
  159. }
  160.  
  161. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  162. {
  163.     CDialog::DoDataExchange(pDX);
  164.     //{{AFX_DATA_MAP(CAboutDlg)
  165.     //}}AFX_DATA_MAP
  166. }
  167.  
  168. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  169.     //{{AFX_MSG_MAP(CAboutDlg)
  170.         // No message handlers
  171.     //}}AFX_MSG_MAP
  172. END_MESSAGE_MAP()
  173.  
  174. // App command to run the dialog
  175. void CSerwebApp::OnAppAbout()
  176. {
  177.     CAboutDlg aboutDlg;
  178.     aboutDlg.DoModal();
  179. }
  180.  
  181. /////////////////////////////////////////////////////////////////////////////
  182. // CSerwebApp commands
  183.